<template>
  <div id="center">
    <div class="up">
      <div style="font-size: 30px;margin-bottom: 5px;margin-top: 20px;font-weight: bold" class="ml-1 mt-2 pl-3">
        {{ dateYear }} {{ dateWeek }} {{ dateDay }}
      </div>
      <div
        class="bg-color-black item" style="font-family: 微软雅黑;font-weight: bold"
        v-for="item in titleItem"
        :key="item.title"
      >
        <p class="ml-1 mt-2 pl-3" style="font-size: 30px;margin-left: 140px;width: 400px;margin-top: 10px;">
          {{ item.title }}</p>
        <div style="font-size: 30px;width: 400px;margin: 0 auto;margin-left: 140px;" class="ml-1 mt-2 pl-3">
          {{ item.number }}
        </div>
      </div>
    </div>
    <div class="down">
      <div class="ranking bg-color-black">
        <span>
          <icon name="chart-pie" class="text-icon"></icon>
        </span>
        <span class="fs-xl text mx-2 mb-1 pl-3">碳排放目标进度榜</span>
        <dv-scroll-ranking-board class="dv-scr-rank-board mt-1" :config="ranking"/>
      </div>
      <div class="percent">
        <div class="item bg-color-black">
          <span>临近目标碳排放</span>
          <CenterChart
            :id="rate[0].id"
            :tips="rate[0].tips"
            :colorObj="rate[0].colorData"
          />
        </div>
        <div class="item bg-color-black">
          <span>次近目标碳排放</span>
          <CenterChart
            :id="rate[1].id"
            :tips="rate[1].tips"
            :colorObj="rate[1].colorData"
          />
        </div>
        <div class="water">
          <dv-water-level-pond class="dv-wa-le-po" :config="water"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CenterChart from '@/components/echart/center/centerChartRate'
import {formatTime} from "@/utils/index1";
import {curYearEmission, queryEmissionMonth} from "@/api/carbon-manage/data";
import {queryTwoHighTarget} from "@/api/carbon-manage/target";

export default {
  data() {
    return {
      timing: null,//todo 碳目标排放率
      loading: true,
      dateDay: null,
      dateYear: null,
      dateWeek: null,
      weekday: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
      decorationColor: ['#568aea', '#000000'],
      titleItem: [
        {
          title: '二氧化碳总排放量',
          number: "12322222222222412.123124214"
        },
        {
          title: '',
          number: ""
        },

      ],
      ranking: {
        data: [],
        carousel: 'single',
        unit: '%'
      },
      water: {
        data: [10, 0],
        shape: 'roundRect',
        formatter: '{value}%',
        waveNum: 3
      },
      // 通过率和达标率的组件复用数据
      rate: [
        {
          id: 'centerRate1',
          tips: 11,
          colorData: {
            textStyle: '#3fc0fb',
            series: {
              color: ['#00bcd44a', 'transparent'],
              dataColor: {
                normal: '#03a9f4',
                shadowColor: '#97e2f5'
              }
            }
          }
        },
        {
          id: 'centerRate2',
          tips: 40,
          colorData: {
            textStyle: '#67e0e3',
            series: {
              color: ['#faf3a378', 'transparent'],
              dataColor: {
                normal: '#ff9800',
                shadowColor: '#fcebad'
              }
            }
          }
        }
      ]
    }
  },
  components: {
    CenterChart
  },
  mounted: function () {
    queryTwoHighTarget().then(res => {
      let v1 = 0;
      for (let i = 0; i < res.data.length; i++) {
        v1 += parseFloat(res.data[i].currentPercent);
      }
      this.water = {
        data: [0, v1 / res.data.length],
        shape: 'roundRect',
        formatter: '{value}%',
        waveNum: 3
      };
      this.rate = [
        {
          id: 'centerRate1',
          tips: parseFloat(res.data[0].currentPercent),
          colorData: {
            textStyle: '#3fc0fb',
            series: {
              color: ['#00bcd44a', 'transparent'],
              dataColor: {
                normal: '#03a9f4',
                shadowColor: '#97e2f5'
              }
            }
          }
        },
        {
          id: 'centerRate2',
          tips: parseFloat(res.data[1].currentPercent),
          colorData: {
            textStyle: '#67e0e3',
            series: {
              color: ['#faf3a378', 'transparent'],
              dataColor: {
                normal: '#ff9800',
                shadowColor: '#fcebad'
              }
            }
          }
        }
      ];
    });
    this.timeFn();

    curYearEmission().then(res => {
      this.titleItem = [
        {
          title: '年累计二氧化碳排放量',
          number: res.data
        },
        {
          title: '',
          number: ""
        },

      ]
    })

    queryEmissionMonth().then(res => {
      console.log(res)
      let data = res.data;
      let arr = [];
      for (let i = 0; i < data.length; i++) {
        var a = data[i];
        arr.push({name: a.name, value: a.currentPercent})
      }
      console.log(arr)
      this.ranking = {
        data: arr,
        carousel: 'single',
        unit: '%'
      };
    });

  },
  methods: {
    timeFn() {
      this.timing = setInterval(() => {
        this.dateDay = formatTime(new Date(), 'HH: mm: ss')
        this.dateYear = formatTime(new Date(), 'yyyy-MM-dd')
        this.dateWeek = this.weekday[new Date().getDay()]
      }, 1000)
    },
  }
}
</script>

<style lang="scss" scoped>
#center {
  display: flex;
  flex-direction: column;

  .up {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;

    .item {
      border-radius: 6px;
      padding-top: 8px;
      margin-top: 8px;
      width: 98%;
      height: 70px;

      .dv-dig-flop {
        width: 150px;
        height: 30px;
      }
    }
  }

  .down {
    padding: 6px 4px;
    padding-bottom: 0;
    width: 100%;
    display: flex;
    height: 255px;
    justify-content: space-between;

    .bg-color-black {
      border-radius: 5px;
    }

    .ranking {
      padding: 10px;
      width: 59%;

      .dv-scr-rank-board {
        height: 225px;
      }
    }

    .percent {
      width: 40%;
      display: flex;
      flex-wrap: wrap;

      .item {
        width: 50%;
        height: 120px;

        span {
          margin-top: 8px;
          font-size: 14px;
          display: flex;
          justify-content: center;
        }
      }

      .water {
        width: 100%;

        .dv-wa-le-po {
          height: 120px;
        }
      }
    }
  }
}
</style>
